package com.imooc.filters;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import java.io.IOException;

/**
 * @author Created By Houce
 * @date 2020-07-16 14:47
 */
public class TestFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("测试过滤器开始初始化===============================");
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("TestFilter starts to filter=====================");
        long start = System.currentTimeMillis();
        //执行过滤
        filterChain.doFilter(servletRequest, servletResponse);
        long time = System.currentTimeMillis() - start;
        System.out.println("time = " + time);
        System.out.println("TestFilter finish filtering=====================");
    }

    @Override
    public void destroy() {
        System.out.println("测试过滤器已经销毁===============================");
    }
}
